package com.hmdp.askPack.controller;

import com.hmdp.askPack.threadLocals.StringHolder;
import com.hmdp.dto.Result;
import org.apache.catalina.startup.RealmRuleSet;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

@RestController
@RequestMapping("/ask/tl")
public class ThreadLoaclController {

    @PostMapping
    public Result setObject(String s) {
        StringHolder.setString(s);
        return Result.ok(s);
    }

    @GetMapping
    public Result getObject(){
        String s = StringHolder.getString();
        if (s == null)
            return Result.fail("thread local don't exit object!");
        return Result.ok(s);
    }
}
